<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:58
 */
namespace app\admin\model;

class BuyorderModel extends BaseModel
{
    protected $table = "xst_buy_order";
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
    /**会员买单*/
    public function mumberbuy_index($condition=1)
    {
        $order_number = input('order_number');
        if(!empty($order_number)){
            $condition = "order_number = $order_number";
        }
        $data = $this->order('createtime desc')->where('type','1')->where('member','1')->where('status','neq','5')->where($condition)->paginate(10,false,['query'=>request()->param()]);
        foreach ($data as $key=>$val)
        {
            $way = explode(',',$val['way']);
            $ways=[];
            foreach ($way as $k=>$value)
            {
                switch ($value){
                    case 1:
                        $ways[$k] = '微信';
                        break;
                    case 2:
                        $ways[$k] = '支付宝';
                        break;
                    case 3:
                        $ways[$k] = '银行卡';
                        break;
                }
            }
            $data[$key]['way']=implode(',',$ways);
        }
        return $data;
    }
    /**会员卖单*/
    public function mumbersell_index($condition=1)
    {
        $order_number = input('order_number');
        if(!empty($order_number)){
            $condition = "order_number = $order_number";
        }
        $data = $this->order('createtime desc')->where('type','2')->where('member','1')->where('status','neq','5')->where($condition)->paginate(10,false,['query'=>request()->param()]);
        foreach ($data as $key=>$val)
        {
            $way = explode(',',$val['way']);
            $ways=[];
            foreach ($way as $k=>$value)
            {
                switch ($value){
                    case 1:
                        $ways[$k] = '微信';
                        break;
                    case 2:
                        $ways[$k] = '支付宝';
                        break;
                    case 3:
                        $ways[$k] = '银行卡';
                        break;
                }
            }
            $data[$key]['way']=implode(',',$ways);
        }
        return $data;
    }
       /**申诉*/
    public function appeal($condition=1)
    {
        $order_number = input('order_number');
        if(!empty($order_number)){
            $condition = "order_number = $order_number";
        }
      $data = $this->order('createtime desc')->where('status','5')->where('member','1')->where($condition)->paginate(10,false,['query'=>request()->param()]);
        foreach ($data as $key=>$val)
        {
            $way = explode(',',$val['way']);
            $ways=[];
            foreach ($way as $k=>$value)
            {
                switch ($value){
                    case 1:
                        $ways[$k] = '微信';
                        break;
                    case 2:
                        $ways[$k] = '支付宝';
                        break;
                    case 3:
                        $ways[$k] = '银行卡';
                        break;
                }
            }
            $data[$key]['way']=implode(',',$ways);
        }
        return $data;
    }
    /**详情*/
    public function buy_list($id)
    {
       $data = $this->where('id',$id)->find();

            $way = explode(',',$data['way']);
            $ways=[];
            foreach ($way as $k=>$value)
            {
                switch ($value){
                    case 1:
                        $ways[$k] = '微信';
                        break;
                    case 2:
                        $ways[$k] = '支付宝';
                        break;
                    case 3:
                        $ways[$k] = '银行卡';
                        break;
                }
            }
            $data['way']=implode(',',$ways);
        return $data;
    }
   /**修改**/
    public function order_update($date,$upd)
    {
        $update = $this->where($date)->update($upd);
        return $update;
    }
}